.POSIX:
SRC=	tkhdr.tcl auplay.tcl tkplay.tcl
PREFIX=	/usr/local
MANDIR=	man

default: tkplay
all: default README
tkplay: ${SRC} Makefile
	cat ${SRC} > $@
	chmod 755 $@
tkhdr.tcl: Makefile
	@if echo exit | tclsh 2>/dev/null; then		\
		tclsh=tclsh;				\
	elif echo exit | tclsh8.6 2>/dev/null; then	\
		tclsh=tclsh8.6;				\
	fi;						\
	printf '#!/bin/sh\n#\\\nexec %s "$$0" "$$@"\n' "$$tclsh"> $@
README: tkplay.1 Makefile
	mandoc -Ios= -Tutf8 tkplay.1 |\
	    awk '{gsub(/.\b/,"");a=b;b=c;c=$$0}FNR>4{print a}' > $@
install: tkplay
	${INSTALL} -m 755 tkplay ${DESTDIR}${PREFIX}/bin/
	${INSTALL} -m 444 tkplay.1 ${DESTDIR}${PREFIX}/${MANDIR}/man1/
install-local: tkplay
	install -m 755 tkplay ${HOME}/bin/
clean:
	rm -f tkplay tkhdr.tcl
clean-all: clean
	rm -f README
